package com.zjj.learn.designmodel.pattern.singleton.demo4;

/** 双重检查锁实现单例模式
 * *** @author zjj_admin
 * *** 2022/4/5 15:52
 */
public class Singleton {

    //私有化构造方法
    private Singleton(){
    }


    //声明对象
    private volatile static Singleton instance;

    //向外暴露可以访问的公共方法
    public static Singleton getInstance(){
        if (null == instance){
            synchronized (Singleton.class){
                if (null == instance){
                   instance =   new Singleton();
                }
            }
        }
        return instance;
    }
}
